package model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;

import Main.Mysql;

public class Terme {
	private int id;
	private String terme;
	private List<PositionsTerme> noeudsPlusPosition;
	private static Mysql bdd;
	
	public Terme (int id, String terme) {
		this.id = id;
		this.terme = terme;
		noeudsPlusPosition = new ArrayList<PositionsTerme>();
		bdd = Mysql.getInstance();
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getTerme() {
		return terme;
	}

	public void setTerme(String terme) {
		this.terme = terme;
	}

	private PositionsTerme getPositionTermeByIdNoeud (int idNoeud) {
		for(int i=0; i<noeudsPlusPosition.size();i++) {
			if (noeudsPlusPosition.get(i).getIdNoeud()== idNoeud) {
				return noeudsPlusPosition.get(i);
			}
		}
		return null;
	}
	
	public List<Integer> getPositionsByNoeudID(int idNoeud) {
		PositionsTerme p = getPositionTermeByIdNoeud(idNoeud);
		if (p == null) {
			ArrayList<Integer> vide = new ArrayList<Integer>();
			return vide;
		} else {
			return p.getPositions();
		}
	}

	public void insertNoeudPlusPosition (int idNoeud, int position) {
		PositionsTerme p = getPositionTermeByIdNoeud(idNoeud);
		if (p != null) {
			p.addPosition(position);
		}
	}

	public void insertListePositionsForNoeud (int idNoeud, List<Integer> position) {
		PositionsTerme p = getPositionTermeByIdNoeud(idNoeud);
		if (p != null) {
			for (int i=0;i<position.size();i++) {
				p.addPosition(position.get(i));
			}
		}
	}
	
	
}
